<script setup lang="ts">
import { storeToRefs } from 'pinia'
import useStore from '../store'
import { ITodoItem } from '../types/data'
import TodoItem from './TodoItem.vue'
const { main } = useStore()
const { getTodos, delTodo, updateTodo,updateAllStatus } = main
const { list, mainRadioStaus } = storeToRefs(main)
const handleChangeInput = (item: ITodoItem) => {
  updateTodo(item.id, 'done', !item.done)
}
const handleChangeAll = (done:boolean) => {
  updateAllStatus(done)
}
getTodos()
</script>
<template>
  <section class="main">
    <input id="toggle-all" class="toggle-all" type="checkbox" :checked="mainRadioStaus" @change="handleChangeAll(!mainRadioStaus)" />
    <label for="toggle-all">Mark all as complete</label>
    <ul class="todo-list">
      <!-- These are here just to show the structure of the list items -->
      <!-- List items should get the class `editing` when editing and `completed` when marked as completed -->
      <TodoItem v-for="item in list" :key="item.id" :item="item"/>
    </ul>
  </section>
</template>